package com.mpyy.handler.purchase;

import com.alibaba.fastjson.JSON;
import com.mpyy.pojo.ProductInfo;
import com.mpyy.service.purchase.SelectProInfoServiceInter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @version 1.0
 * @Descoription SelectProHandlerInfo
 * @Author CG
 * @date 2022-03-10
 */
@Controller
public class SelectProHandlerInfo {
    @Autowired
    @Qualifier(value = "selectProInfoServiceImpl")
    private SelectProInfoServiceInter selectProInfoService;

    /** 模糊查询和查询全部商品
     *
     * @param productInfo
     * @return
     */
    @RequestMapping(value = {"/selectProInfo"})
    @ResponseBody
    public String selectProInfo(ProductInfo productInfo){
        //调用业务逻辑层
        List<ProductInfo> productInfos = selectProInfoService.selectProInfoDao(productInfo.getProName(),productInfo.getProName());
        int count = selectProInfoService.productCount();
        //创建一个Map集合保存数据 并转换成JSON格式传递到页面
        Map<Object,Object> map = new HashMap<>();
        map.put("code",0);
        map.put("msg","");
        map.put("count",count);
        map.put("data",productInfos);
//        System.out.println(JSON.toJSONString(map));
        return JSON.toJSONString(map);
    }

    /**根据上级商品分类ID查询商品信息
     * @param productInfo
     * @return
     */
    @RequestMapping(value = {"/selectProInfoClassify"})
    @ResponseBody
    public  String   selectProInfoClassify(ProductInfo productInfo ){
        //调用业务逻辑层并将数据保存到List集合中
        List<ProductInfo> productInfoObj = selectProInfoService.selectProInfoClassify(productInfo);
        int count = selectProInfoService.productCount();
        //创建一个Map集合保存数据 并转换成JSON格式传递到页面
        Map<Object,Object> map = new HashMap<>();
        map.put("code",0);
        map.put("msg","");
        map.put("count",count);
        map.put("data",productInfoObj);
//        System.out.println(JSON.toJSONString(map));
        return JSON.toJSONString(map);
    }
}
